package com.ruoyi.information.controller.back;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.information.domain.back.ApplyContactBack;
import com.ruoyi.information.service.back.IApplyContactBackService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 一键联系Controller
 * 后台
 * @author ruoyi
 * @date 2023-05-16
 */
@RestController
@RequestMapping("/contactBack")
public class ApplyContactBackController extends BaseController
{
    @Autowired
    private IApplyContactBackService applyContactService;

    /**
     * 查询一键联系列表
     */
    @RequiresPermissions("information:contact:list")
    @GetMapping("/list")
    public TableDataInfo list(ApplyContactBack applyContact)
    {
        startPage();
        List<ApplyContactBack> list = applyContactService.selectApplyContactList(applyContact);
        return getDataTable(list);
    }

    /**
     * 导出一键联系列表
     */
    @RequiresPermissions("information:contact:export")
    @Log(title = "一键联系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApplyContactBack applyContact)
    {
        List<ApplyContactBack> list = applyContactService.selectApplyContactList(applyContact);
        ExcelUtil<ApplyContactBack> util = new ExcelUtil<ApplyContactBack>(ApplyContactBack.class);
        util.exportExcel(response, list, "一键联系数据");
    }

    /**
     * 获取一键联系详细信息
     */
    @RequiresPermissions("information:contact:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(applyContactService.selectApplyContactById(id));
    }

    /**
     * 新增一键联系
     */
    @RequiresPermissions("information:contact:add")
    @Log(title = "一键联系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApplyContactBack applyContact)
    {
        return toAjax(applyContactService.insertApplyContact(applyContact));
    }

    /**
     * 修改一键联系
     */
    @RequiresPermissions("information:contact:edit")
    @Log(title = "一键联系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApplyContactBack applyContact)
    {
        return toAjax(applyContactService.updateApplyContact(applyContact));
    }

    /**
     * 删除一键联系
     */
    @RequiresPermissions("information:contact:remove")
    @Log(title = "一键联系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(applyContactService.deleteApplyContactByIds(ids));
    }
}
